package behavioral.pattern.chain;

import behavioral.pattern.chain.filters.FilterAbs;

import java.util.ArrayList;
import java.util.List;

/**
 * @Autor: yuanyongan
 * @Description: 职责链模式
 * @Date 2023/1/10 9:03
 */
public class FilterChain {
    // 当前执行到了哪个filter
    private int pos = 0;
    // filter的总数
    private int n;
    private List<FilterAbs> filters = new ArrayList<>();

    // 递归执行所有filter
    public void doFilter(){
        if (pos < n){
            FilterAbs filter = filters.get(pos++);
            filter.doFilter();
            doFilter();
        }
    }
    public void addFilter(FilterAbs filter){
        filters.add(filter);
        n++;
    }
}
